//==========================================================================================
//
//		OpenNETCF.Win32.Core
//		Copyright (c) 2003, OpenNETCF.org
//
//		This library is free software; you can redistribute it and/or modify it under 
//		the terms of the OpenNETCF.org Shared Source License.
//
//		This library is distributed in the hope that it will be useful, but 
//		WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
//		FITNESS FOR A PARTICULAR PURPOSE. See the OpenNETCF.org Shared Source License 
//		for more details.
//
//		You should have received a copy of the OpenNETCF.org Shared Source License 
//		along with this library; if not, email licensing@opennetcf.org to request a copy.
//
//		If you wish to contact the OpenNETCF Advisory Board to discuss licensing, please 
//		email licensing@opennetcf.org.
//
//		For general enquiries, email enquiries@opennetcf.org or visit our website at:
//		http://www.opennetcf.org
//
//==========================================================================================
using System;
using System.ComponentModel;
using System.Runtime.InteropServices;
using System.Text;
using System.Reflection;

namespace OpenNETCF.Win32
{
	
	/// <summary>
	/// OpenNETCF Win32 API Wrapper Class for CoreDLL.dll
	/// </summary>
	/// <remarks>For illustrating the control hosting code this class contains only a tiny subset of functionality from the Smart Device Framework.</remarks>
	public sealed class Core
	{   
		private Core(){}
		
		/// <summary>
		/// Wrapper around GetModuleHandle Win32 function
		/// </summary>
		/// <param name="module">Module name</param>
		/// <returns>Module handle or IntPtr.Zero, if not in memory </returns>
		public static IntPtr GetModuleHandle(string module)
		{
			return GetModuleHandleCE(module);
		}

		/// <summary>
		/// Wrapper around LoadLibrary Win32 function
		/// </summary>
		/// <param name="library">Library module name</param>
		/// <returns>hModule or error code</returns>
		public static IntPtr LoadLibrary(string library)
		{
			IntPtr ret = LoadLibraryCE(library);
			if ( ret.ToInt32() <= 31 & ret.ToInt32() >= 0)
				throw new Win32Exception(Marshal.GetLastWin32Error(), "Failed to load library " + library);
			return ret;
		}

		[DllImport("coredll.dll", EntryPoint="GetModuleHandleW", SetLastError=true)]
		internal static extern IntPtr GetModuleHandleCE(string lpszModule);
		
		[DllImport("coredll.dll", EntryPoint="LoadLibraryW", SetLastError=true)]
		internal static extern IntPtr LoadLibraryCE( string lpszLib );
	}

}

/* ============================== Change Log ==============================
 * see Changelog.txt
 * ======================================================================== */
